<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <!-- <h3>
            {{ val + '!!!' }} 
        </h3>

        <h3>
            {{ val + '!!!' }} 
        </h3>

        <h3>
            {{ val + '!!!' }} 
        </h3> -->

        <!-- <h3>
            {{ changeVal() }} 
        </h3>
        <h3>
            {{ changeVal() }} 
        </h3>
        <h3>
            {{ changeVal() }} 
        </h3> -->

        <input v-model="val" type="text">

        <h3>
            {{ newVal }}
        </h3>

        <h3>
            {{ newVal }}
        </h3>

        <h3>
            {{ newVal }}
        </h3>


        <button @click="fn">按钮</button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>

        new Vue({
            // 元素
            el: "#app",
            // 定义的数据(状态)
            data: {
                val: '我是初始数据'
            },
            methods: {
                changeVal() {
                    console.log(1)
                    return this.val + '!!!!'
                },
                fn() {
                    console.log(this)
                }
            },
            // 计算属性 --- ( 添加到this)
            // 必须要return

            // 1. 缓存
            // 2. 当依赖项不发生改变是不会重新进行计算
            computed: {
                newVal() {
                    console.log(1)
                    return this.val + '!!!!'
                }
            }
        })
    </script>
</body>

</html>